﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NENAData.Events;
using NENAData.NENAMember;
using NENAData.Transactions.Payments;

namespace Events
{
    public partial class MyEventDetails2012 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            //must pass in the conferenceID and member ID


            int intMemberId = Convert.ToInt32(Request.QueryString["MemberId"]);
            if (intMemberId == 0)
                Response.Redirect("http://events.nena.ca", true);

            int intEventId = Convert.ToInt32(Request.QueryString["EventId"]);
            if (intEventId == 0)
                Response.Redirect("http://events.nena.ca", true);

            EventRegistration oER = new EventRegistration();
            //var socialRegistrations = oER.GetAllSocialRegistrations(1050, 6);
            var socialRegistrations = oER.GetAllSocialRegistrations(intMemberId);
            TextboxSocialTickets.Text = socialRegistrations.Count.ToString();

            var eventRegistration = oER.Get(intMemberId, intEventId);
            TextboxComments.Text = eventRegistration.Comments.ToString();

            SessionRegistration oSR = new SessionRegistration();
            var sessionRegistrations = oSR.GetWithSlotSession(eventRegistration.EventRegistrationID);

            Payments oPayment = new Payments();
            var oCompletedPayment = oPayment.GetTransactionPayment_byTransactionPaymentID(eventRegistration.TransactionPayment.TransactionPaymentID);
            TextboxTotalPaid.Text = "$" + oCompletedPayment.PaymentAmount.ToString();
                        
            foreach (var item in sessionRegistrations)
            {
                //Response.Write(item.SlotSession.Description.ToString() + "<br />");
            }

            var s = (from NENAData.EF.EventSessionRegistration ss in sessionRegistrations
                     select ss.SlotSession).ToList();
            //var SlotSessions = sessionRegistrations.SelectMany(d => d.SlotSession).ToList();
            GridView1.DataSource = s;
            GridView1.DataBind();

            SetupDefaults();
        }

        private void SetupDefaults()
        {
            NENAMember oNenaData = new NENAMember();
            var oMember = oNenaData.GetMember(Convert.ToInt32(Request.QueryString["MemberId"]));

            PersonalFirstName.Text = oMember.FirstName;
            PersonalLastName.Text = oMember.LastName;
            PersonalHomePhone.Text = oMember.HomePhone;
            PersonalCity.Text = oMember.City;
            PersonalPostalCode.Text = oMember.PostalCode;
            PersonalProvince.Text = oMember.Province;
            PersonalEmail.Text = oMember.EmailAddress;
            PersonalAddress1.Text = oMember.Address;
            PersonalAddress2.Text = oMember.Address2;

            //ListEvents();
            //LoadSessions();
            //SetConferenceFee();
            //CalculateRegistrationFee(null, null);
        }

    }
}